package seperator;

import java.util.ArrayList;

import utility.DataFilter;
import words.Noun;
import words.Quotation;

public class NounSeperator extends SeperatorAbstract{
	private Noun noun;
	public NounSeperator()
	{
		this.noun = new Noun();
	}

	public void seperate()
	{
		String data[] = super.getData();
		ArrayList<String[]> temp_list = new ArrayList<String[]>();
		for(int i = 0 ; i < data.length ; i ++)
		{
			// to check the first character is the uppercase
			char c = 'a';
			if(!data[i].isEmpty())
			{
				 c = data[i].charAt(0);
			}
			
			if(Character.isUpperCase(c))
			{
				ArrayList<String> noun_word = new ArrayList<String>();
				int count = 0;
				
				while(Character.isUpperCase(c))
				{
					noun_word.add(data[i]);
					c = data[++i].charAt(0);
					count++;
				}
				if(count > 1)
				{
					String [] legal_word = noun_word.toArray(new String[noun_word.size()]);
					// if the word is in the list, dont add
					String [][] list = temp_list.toArray(new String[temp_list.size()][]);
					if(!DataFilter.isexisted(legal_word, list))
					{
						temp_list.add(legal_word);
					}
					
				}
			}
		}
		for(int i = 0 ; i < temp_list.size() ; i ++)
		{
			noun.input(temp_list.get(i));
		}
		
	}
	public Noun getResult()
	{
		return this.noun;
	}
}

	

